package 墙的重建;

import java.util.Arrays;
import java.util.Scanner;

public class Main {
    static int N = 110, M = 1010;
    static int[] h = new int[N];
    static int[] s = new int[M];
    static int[][] f = new int[N][N];
    static int[][] g = new int[N][N];

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int T = in.nextInt();
        for (int cases = 1; cases <= T; cases++) {
            int n = in.nextInt();
            int m = in.nextInt();
            for (int i = 1; i <= n; i++) {
                h[i] = in.nextInt();
            }
            for (int i = 1; i <= n; i++) {
                Arrays.fill(s, 0);
                for (int j = i, maxv = 0; j <= n; j++) {
                    s[h[j]]++;
                    maxv = Math.max(maxv, s[h[j]]);
                    g[i][j] = j - i + 1 - maxv;
                }
            }
            for (int i = 1; i <= n; i++) {
                Arrays.fill(f[i], 0x3f3f3f3f);
            }
            for (int i = 1; i <= n; i++) {
                for (int j = 1; j <= m + 1; j++) {
                    for (int k = 1; k <= i; k++) {
                        f[i][j] = Math.min(f[i][j], f[k - 1][j - 1] + g[k][i]);
                    }
                }
            }
            System.out.printf("Case #%d: %d\n", cases, f[n][m + 1]);
        }
    }
}
